from flask import Flask
from flask_sqlalchemy import SQLAlchemy
import os
app = Flask(__name__)

# 设置 SQLite 数据库路径
db_dir = os.path.join(os.path.curdir) # 数据库目录
os.makedirs(db_dir, exist_ok=True)  # 如果目录不存在则创建
db_path = os.path.join(db_dir, 'example.db')  # 拼接数据库路径

app.config['SQLALCHEMY_DATABASE_URI'] = f'sqlite:///{db_path}'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

db = SQLAlchemy(app)
class cfg:
    TASK_STATUS_WAITING = 0
    TASK_STATUS_RUNNING = 1
    TASK_STATUS_SUCCESS = 2
    TASK_STATUS_FAILED = 3
# 示例模型
class User(db.Model):
    task_id = db.Column(db.String(80), primary_key=True)
    status = db.Column(db.Integer, default=cfg.TASK_STATUS_WAITING)
    def __init__(self, task_id,status):
        self.task_id = task_id
        self.status = status